/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxinline.servico;

import br.com.foxinline.enums.Relatorios;
import br.com.foxinline.modelo.Anexo;
import br.com.foxinline.modelo.Processo;
import br.com.foxinline.modelo.Protocolo;
import br.com.foxinline.utilitarios.VOAnnex;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.ejb.Stateless;

/**
 *
 * @author laverson
 */
@Stateless
public class AnexoServico extends ServicoGenerico<Anexo> {

    public AnexoServico() {
        super(Anexo.class);
    }

    @Override
    public void salvar(Anexo entity) {
        entity.setArquivo(null);
        super.salvar(entity);
    }

    public void genReportAnnex(Protocolo protocolo) {

        HashMap<String, Object> parametros;
        parametros = new HashMap<String, Object>();
        InputStream imgInputStream = null;
        List<VOAnnex> annexs = new ArrayList<VOAnnex>();
        for (Processo processo : protocolo.getProcessos()) {
            for (Anexo anexo : processo.getAnexos()) {
                imgInputStream = new ByteArrayInputStream(anexo.getArquivo());
                annexs.add(new VOAnnex(imgInputStream));
            }
        }

        RelatorioServico.genReport(parametros, annexs, Relatorios.ANNEX);
    }
}
